package org.bluweb.g4wicket.translate;

import java.util.HashMap;
import java.util.Map;

import org.apache.wicket.behavior.SimpleAttributeModifier;
import org.apache.wicket.markup.html.IHeaderResponse;
import org.bluweb.g4wicket.G4WicketComponent;

@SuppressWarnings("serial")
public class TranslateElement extends G4WicketComponent {

	private String pageLanguage;
	
	public TranslateElement( String id, String pageLanguage ) {
		super( id );
		this.pageLanguage = pageLanguage;
		this.add( new SimpleAttributeModifier( "style", "display:block" ) );
	}

	@Override
	public void renderHead(IHeaderResponse response) {
		super.renderHead( response );
		response.renderJavascriptReference( "http://translate.google.com/translate_a/element.js" );
	}

	@Override
	protected void onBeforeRender() {
		super.onBeforeRender();
		
		Map<String,Object> parameters = new HashMap<String, Object>();
		parameters.put( "pageLanguage", pageLanguage );
		
		this.setJavaScriptTemplate( "TranslateElement.js", true, parameters );
	}
}
